package com.ruoyi.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.domain.MtrStock;
import com.ruoyi.mes.service.IMtrStockService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物料库存Controller
 *
 * @author LongAndHao
 * @date 2023-04-04
 */
@Api(tags = "物料库存")
@RestController
@RequestMapping("/mes/mtrstock")
public class MtrStockController extends BaseController
{
    @Autowired
    private IMtrStockService mtrStockService;

    /**
     * 查询物料库存列表
     */    @ApiOperation(value = "查询物料库存列表")
    @PreAuthorize("@ss.hasPermi('mes:mtrstock:list')")
    @GetMapping("/list")
    public TableDataInfo list(MtrStock mtrStock)
    {
        startPage();
        List<MtrStock> list = mtrStockService.selectMtrStockList(mtrStock);
        return getDataTable(list);
    }

    /**
     * 导出物料库存列表
     */    @ApiOperation(value = "导出物料库存列表")
    @PreAuthorize("@ss.hasPermi('mes:mtrstock:export')")
    @Log(title = "物料库存", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MtrStock mtrStock)
    {
        List<MtrStock> list = mtrStockService.selectMtrStockList(mtrStock);
        ExcelUtil<MtrStock> util = new ExcelUtil<MtrStock>(MtrStock.class);
        util.exportExcel(response, list, "物料库存数据");
    }

    /**
     * 获取物料库存详细信息
     */    @ApiOperation(value = "获取物料库存详细信息")
    @PreAuthorize("@ss.hasPermi('mes:mtrstock:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mtrStockService.selectMtrStockById(id));
    }

    /**
     * 新增物料库存
     */    @ApiOperation(value = "新增物料库存")
    @PreAuthorize("@ss.hasPermi('mes:mtrstock:add')")
    @Log(title = "物料库存", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MtrStock mtrStock)
    {
        return mtrStockService.insertMtrStock(mtrStock);
    }

    /**
     * 修改物料库存
     */    @ApiOperation(value = "修改物料库存")
    @PreAuthorize("@ss.hasPermi('mes:mtrstock:edit')")
    @Log(title = "物料库存", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MtrStock mtrStock)
    {
        return toAjax(mtrStockService.updateMtrStock(mtrStock));
    }

    /**
     * 删除物料库存
     */    @ApiOperation(value = "删除物料库存")
    @PreAuthorize("@ss.hasPermi('mes:mtrstock:remove')")
    @Log(title = "物料库存", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mtrStockService.deleteMtrStockByIds(ids));
    }
}
